﻿//自动义双击方法
function CustomDbClick() {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    var vid = record.getData("ID");
    if (vid != "") {
        window.parent.$("#tabs").tabs('close', '查看缴款单信息');
        var pagetitle = "查看缴款单信息";
        parent.addTabs(pagetitle, '../Crm/Modules/AddPay.aspx?r=' + Math.random() + '&view=checks&flag=1&entity=' + const_EditEntity + '&id=' + vid + '&title=' + encodeURI(pagetitle));
        parent.NeedRefreshPage = this;
    }
}
//自定义新增方法
var queryString = function (key) {
    return (document.location.search.match(new RegExp("(?:^\\?|&)" + key + "=(.*?)(?=&|$)")) || ['', null])[1];
}
var fnCustomAdd = function () {
    window.parent.$("#tabs").tabs('close', '起草缴款单');
    var pagetitle = "起草缴款单";
    if (queryString("condition") != null || queryString("condition") == "") {
        var tempHis = queryString("condition");
        tempHis = tempHis.substr(0, 4);
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?history=' + tempHis + '&title=&WorktaskId=6517f422-70ea-477d-a9b3-07ff55f129eb&WorkflowId=17972549-9867-4ad8-8cdf-e6141a9af6f0');
    } else {
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?title=&WorktaskId=6517f422-70ea-477d-a9b3-07ff55f129eb&WorkflowId=17972549-9867-4ad8-8cdf-e6141a9af6f0');
    }
    parent.NeedRefreshPage = this;
}
//分公司缴款
var fnAddNew2 = function () {
    window.parent.$("#tabs").tabs('close', '起草缴款单');
    var pagetitle = "起草缴款单";
    if (queryString("condition") != null || queryString("condition") == "") {
        var tempHis = queryString("condition");
        tempHis = tempHis.substr(0, 4);
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?history=' + tempHis + '&title=&WorktaskId=6517f422-70ea-477d-a9b3-07ff55f129eb&WorkflowId=17972549-9867-4ad8-8cdf-e6141a9af6f0');
    } else {
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?title=&WorktaskId=6517f422-70ea-477d-a9b3-07ff55f129eb&WorkflowId=17972549-9867-4ad8-8cdf-e6141a9af6f0');
    }
    parent.NeedRefreshPage = this;
}
//总部缴款
var fnAddGain = function () {
    window.parent.$("#tabs").tabs('close', '总部缴款');
    var pagetitle = "总部缴款";
    if (queryString("condition") != null || queryString("condition") == "") {
        var tempHis = queryString("condition");
        tempHis = tempHis.substr(0, 4);
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?history=' + tempHis + '&title=' + encodeURI(pagetitle) + '&WorktaskId=fe006d2e-3172-4ba3-a860-0229e20955e6&WorkflowId=1c6e6e63-6853-445b-b37a-9c5a490103ae');
    } else {
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?title=' + encodeURI(pagetitle) + '&WorktaskId=fe006d2e-3172-4ba3-a860-0229e20955e6&WorkflowId=1c6e6e63-6853-445b-b37a-9c5a490103ae');
    }
    parent.NeedRefreshPage = this;
}
//英才缴款
var fnAddGains = function () {
    window.parent.$("#tabs").tabs('close', '英才缴款');
    var pagetitle = "英才缴款";
    if (queryString("condition") != null || queryString("condition") == "") {
        var tempHis = queryString("condition");
        tempHis = tempHis.substr(0, 4);
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?history=' + tempHis + '&title=' + encodeURI(pagetitle) + '&WorktaskId=93450c47-3c8d-452e-8dcd-549b52df0970&WorkflowId=f194fa95-d47e-43c3-a029-af83d6cbf019');
    } else {
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?title=' + encodeURI(pagetitle) + '&WorktaskId=93450c47-3c8d-452e-8dcd-549b52df0970&WorkflowId=f194fa95-d47e-43c3-a029-af83d6cbf019');
    }
    parent.NeedRefreshPage = this;
}
//佣金操作
var fnPlan = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var stName = record.getData("StateName");
    if (stName == "结案") {
        var vState = record.getData("CommissionState");
        if (vState == "2") {
            alert("该记录已操作");
            return;
        } else {
            var SetManagerURL = "../../Crm/Modules/AddCommission.aspx?r=";
            var vid = record.getData(const_entityID);
            if (vid != undefined && vid != "") {
                var pagetitle = "佣金操作";
                document.getElementById("EditUIWindow").src = SetManagerURL + Math.random() + "&id=" + vid + "&title=" + encodeURI(pagetitle) + "";
                YAHOO.example.container.dialog1.show();
                document.getElementById("yui-gen31-button").style.display = "block";
            }
        }
    } else {
        alert("该缴款单还未签核完毕，不能发放佣金");
        return;
     }
}
//价值业绩操作
var fnCheckOrder = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var stName = record.getData("StateName");
    if (stName == "结案") {
        parent.addTabs('价值业绩申请', '../../Crm/Modules/CrmValueTask.aspx?r=' + Math.random() + '&entity=CrmValue&id=' + record.getData(const_entityID));
        parent.NeedRefreshPage = this;   
    } else {
        alert("该缴款单还未签核完毕，不能申请价值业绩");
        return;
    }
    
}
//直接缴款方法
var fnAddNew1 = function () {
    window.parent.$("#tabs").tabs('close', '现场缴款');
    var pagetitle = "现场缴款";
    if (queryString("condition") != null || queryString("condition") == "") {
        var tempHis = queryString("condition");
        tempHis = tempHis.substr(0, 4);
        parent.addTabs(pagetitle, '../crm/Modules/AddPay.aspx?history=' + tempHis + '&flag=0&type=directPay&title=&entity=CrmPay&wtid=6517f422-70ea-477d-a9b3-07ff55f129eb&wfid=17972549-9867-4ad8-8cdf-e6141a9af6f0');
    } else {
        parent.addTabs(pagetitle, '../crm/Modules/AddPay.aspx?flag=0&type=directPay&title=&entity=CrmPay&wtid=6517f422-70ea-477d-a9b3-07ff55f129eb&wfid=17972549-9867-4ad8-8cdf-e6141a9af6f0');
    }
    parent.NeedRefreshPage = this;
}
//自定义修改方法
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    //if (record == null || record.getData("CheckName") != "") {
    //alert("请选择一条现场缴款单（核算人员为空的记录）");
    if (record == null) {
        alert("请选择一条缴款单");
        return;
    }
    window.parent.$("#tabs").tabs('close', '编辑缴款单信息');
    var cid = record.getData("CustomerId");
    var pagetitle = "编辑缴款单信息";
    if (queryString("condition") != null || queryString("condition") == "") {
        var tempHis = queryString("condition");
        tempHis = tempHis.substr(0, 4);
        parent.addTabs('编辑缴款单信息', '../Crm/Modules/AddPay.aspx?history=' + tempHis + '&flag=1&type=directPay&edit=update&r=' + Math.random() + '&cid=' + cid + '&title=' + encodeURI(pagetitle) + '&entity=CrmPay&id=' + record.getData(const_entityID));
    } else {
        parent.addTabs('编辑缴款单信息', '../Crm/Modules/AddPay.aspx?flag=1&type=directPay&edit=update&r=' + Math.random() + '&cid=' + cid + '&title=' + encodeURI(pagetitle) + '&entity=CrmPay&id=' + record.getData(const_entityID));
    } parent.NeedRefreshPage = this;

}
//自定义删除方法
//var fnCustomDeleteData = function () {
//}

if (typeof ($) == "undefined") { //屏蔽右键
    parent.unContextMenu(document);
    /*$(document).ready(function () { 
    if (typeof (parent.unContextMenu) == "function") {
    parent.unContextMenu(document);
    }
    if (typeof (parent.parent.unContextMenu) == "function") {
    parent.parent.unContextMenu(document);
    }
    });*/
}
if (typeof (YAHOO) == "undefined") {
    parent.unContextMenu(document);
}
//备注过滤
var fnExplain=function(elCell, oRecord, oColumn, sData) {
    sData.replace("[BR]", "");
    if (sData.length > 20) {
        elCell.innerHTML = sData.substring(0, 20) + "..." + "<a href='javascript:CustomDbClick()'>详细</a>";
    }
    else {
        elCell.innerHTML = sData;
    }
};
//格式化佣金状态
var fnPay = function (elCell, oRecord, oColumn, sData) {
    if (sData == "2") {
        elCell.innerHTML = "<font color='red'>已发放完成</font>";
    } else if (sData == "3") {
        elCell.innerHTML = "<font color='red'>已发放部分</font>";
    } else {
        elCell.innerHTML = "<font color='red'>还未发放</font>";;
    }
};
//格式化时间
var fnDate = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0001-01-01 ") {
        elCell.innerHTML = "";
    } else {
        elCell.innerHTML = sData;
    }
 };